<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Report_detail extends CI_Controller
{
	private $ads_conf = array();
	function __construct()
	{
		parent::__construct();
		$this->load->helper('url');
		$this->load->config('report_detail', TRUE);
		$this->load->library('security');
		$this->load->library('tank_auth');
		$this->load->library('backyard_view');
		$this->load->model('adsense/report');
		$this->lang->load('tank_auth');
	}

	function index()
	{
		//$this->load->view('adsense/report_chart');
		//echo 'is_logged_in:';var_dump($this->tank_auth->is_logged_in());exit;
		if (!$this->tank_auth->is_logged_in()) { // not logged in
            redirect('/auth/login');
        
        } else {
        	
        	$data['all_website'] = $this->tank_auth->get_user_website();
            $data['all_website'] = explode('|', $data['all_website']); // explode website to an array
        	
			//echo "<pre>";print_r($this->uri->uri_to_assoc(1));echo "</pre>";
            /*
             * make url parameter into associated structure
             */
            foreach ($this->uri->uri_to_assoc(1) as $key=>$val) {
                $data[$key] = $val;
            }

			
        	$this->load->view('report/detail',$data);
        }
	}
	
	function report_detail_table(){
		/*
		 * default: chart data just fetch click
		 */
		
		$data_detail = $this->report->get_detail_by_website_date($this->input->post('website'),$this->input->post('start_date'),$this->input->post('end_date'),$this->input->post('chart_type'));
		
		$data['website_report_detail'] = $data_detail['website_report_detail'];
        $data['report_detail_table_terms'] = $this->config->item('report_detail_table_terms', 'report_detail');
		
		//echo $this->load->view('report/report_detail_table',$data,true);
		/*
		$data_detail['max_data'] = pow(10,strlen($data_detail['max_data']));
		$data_detail['min_data'] = pow(10,strlen($data_detail['min_data'])-1);
		*/
		//echo $data_detail['max_data']; 
		$data_detail['max_data'] = $data_detail['max_data']+pow(10,strlen(intval($data_detail['max_data']))-1);
		$data_detail['min_data'] = $data_detail['min_data']-pow(10,strlen(intval($data_detail['min_data']))-1);
		
		$ret_data = array('chart_data'=>$data_detail['chart_data'],'table_data'=>$this->load->view('report/report_detail_table',$data,true),'max_data'=>$data_detail['max_data'],'min_data'=>$data_detail['min_data']);
		//$ret_data = array('chart_data'=>$data_detail['chart_data'],'table_data'=>$this->load->view('report/report_detail_table',$data,true));
		
		echo json_encode($ret_data);
	}
	
	function report_chart(){
		//echo $this->load->view('report/report_chart');
		$this->load->view('adsense/report_chart');
	}
	
}

/*
 $json = array(
			array(
				array('2011-10-01', 1120), array('2011-10-02', 435), array('2011-10-03', 23), array('2011-10-28', 600), array('2011-10-31', 20), array('2011-10-4', 40), array('2011-10-5', 50), array('2011-11-01', 112), array('2011-11-02', 435), array('2011-11-03', 23), array('2011-11-28', 600), array('2011-11-31', 20), array('2011-11-4', 40), array('2011-11-5', 50)
			),
			array(
				array('2011-10-01', 1120), array('2011-10-02', 43500), array('2011-10-03', 203), array('2011-10-28', 1600), array('2011-10-31', 420), array('2011-10-4', 400), array('2011-10-5', 507), array('2011-11-01', 1120), array('2011-11-02', 43500), array('2011-11-03', 203), array('2011-11-28', 1600), array('2011-11-31', 420), array('2011-11-4', 400), array('2011-11-5', 507)
				)
		);
		echo json_encode($json);
 */

/* End of file report_detail.php */
/* Location: ./application/controllers/report_detail.php */